<template>
  <div class="user-center">
    <div class="user-container">
      <!-- 左侧边栏 -->
      <aside class="user-sidebar">
        <div class="sidebar-menu">
          <router-link v-for="item in menuItems" :key="item.path" :to="item.path" class="menu-item">
            <el-icon>
              <component :is="item.icon" />
            </el-icon>
            <span>{{ item.label }}</span>
          </router-link>
        </div>
      </aside>

      <!-- 右侧内容区 -->
      <main class="user-content">
        <router-view v-slot="{ Component }">
          <transition name="fade" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </main>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { User, Setting, Document } from '@element-plus/icons-vue'

const menuItems = ref([
  { path: '/user/profile', label: '个人资料', icon: User },
  { path: '/user/settings', label: '账号设置', icon: Setting },
  { path: '/user/orders', label: '我的订单', icon: Document }
])
</script>

<style scoped lang="less">
.user-center {
  height: 100%;
  background: #f5f7fa;
}

.user-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  gap: 24px;
  padding: 24px;
}

.user-sidebar {
  flex: 0 0 220px;
  background: white;
  border-radius: 8px;
  padding: 16px 0;
  height: fit-content;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.sidebar-menu {
  display: flex;
  flex-direction: column;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  color: #333;
  text-decoration: none;
  font-size: 15px;
  transition: all 0.3s;
  position: relative;

  &:hover {
    background: #f5f7fa;
    color: #667eea;
  }

  &.router-link-exact-active {
    color: #667eea;
    background: #f0f2ff;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      width: 3px;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }
  }

  .el-icon {
    font-size: 18px;
  }
}

.user-content {
  flex: 1;
  background: white;
  border-radius: 8px;
  padding: 32px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  min-height: 500px;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.2s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

@media (max-width: 768px) {
  .user-container {
    flex-direction: column;
    padding: 16px;
  }

  .user-sidebar {
    flex: 0 0 auto;
  }

  .sidebar-menu {
    flex-direction: row;
    overflow-x: auto;
  }

  .menu-item {
    flex-direction: column;
    gap: 4px;
    padding: 12px 16px;
    font-size: 13px;
    white-space: nowrap;

    &.router-link-exact-active::before {
      left: 0;
      right: 0;
      top: auto;
      bottom: 0;
      width: auto;
      height: 3px;
    }
  }

  .user-content {
    padding: 20px;
  }
}
</style>
